<!-- start-->
<div class=" edit">

    <!-- 表单 -->   
    <section class="panel-body">
        <form role="form" class="form-edit">
            <input type="hidden" name="id" value="{:$row.id}">

                <div class="form-group col-sm-6">
                    <span>产品编号</span>
                    <input type="text" class="form-control" placeholder="产品编号" name="sn" value="{$row.sn}">
                </div>

                <div class="form-group col-sm-6">
                    <span>内部编号</span>
                    <input type="text" class="form-control" placeholder="内部编号" name="unique_sn" value="{$row.unique_sn}">
                </div>

                <div class="form-group col-sm-6">
                    <span>产品分类</span>
                    <select name="cate" class="form-control comboSelect">
                        <option value="0">顶级</option>
                        {volist name="list" id="vo"}
                            {if($vo.level<2) }
                                <option value="{$vo.id}" {:$row.cate==$vo.id ? 'selected="selected"' : null } >{:$vo.level>0? '|' : null }{:str_repeat('--',$vo.level)}{$vo.name}
                                </option>
                            {else /} {/if}

                        {/volist}
                    </select>
                </div>

                <div class="form-group col-sm-6">
                    <span>产品名称</span>
                    <input type="text" class="form-control" placeholder="产品名称" name="name" value="{$row.name}">
                </div>

                <div class="form-group col-sm-6">
                    <span>品牌</span>
                    <select name="brand" class="form-control comboSelect">
                        {volist name="brand" id="vo"}
                            <option value="{$vo.id}" {:$row.brand==$vo.id ? 'selected="selected"' : null } >{$vo.name}</option>
                        {/volist}
                    </select>
                </div>


                <div class="form-group col-sm-6">
                    <span>型号</span>
                    <input type="text" class="form-control" placeholder="型号" name="model" value="{$row.model}">
                </div>        

                <div class="form-group col-sm-6">
                    <span>规格</span>
                    <input type="text" class="form-control" placeholder="规格" name="spec" value="{$row.spec}">
                </div>                         

                <div class="form-group col-sm-6">
                    <span>默认价格</span>
                    <input type="text" class="form-control" placeholder="默认价格" name="price" value="{$row.price}">
                </div> 

                <div class="form-group col-sm-6">
                    <span>默认供应商</span>
                    <select name="supplier" class="form-control comboSelect">
                        {volist name="supplier" id="vo"}
                            <option value="{$vo.id}" {:$row.supplier==$vo.id ? 'selected="selected"' : null } >{$vo.title}</option>
                        {/volist}
                    </select>
                </div>

                <div class="form-group col-sm-6">
                    <span>默认客户</span>
                    <select name="customer" class="form-control comboSelect">
                        {volist name="customer" id="vo"}
                            <option value="{$vo.id}" {:$row.customer==$vo.id ? 'selected="selected"' : null } >{$vo.title}</option>
                        {/volist}
                    </select>
                </div>

                <div class="form-group col-sm-6">
                    <span>默认库位</span>
                    <select name="location" class="form-control comboSelect" >
                        {volist name="location" id="vo"}
                        <option value="{$vo.id}"  {:$row.location==$vo.id ? 'selected="selected"' : null }>{$vo.name}</option>
                        {/volist}
                    </select>
                </div>                  

                <div class="form-group col-sm-6">
                    <span>计量单位</span>
                    <select name="unit" class="form-control comboSelect">
                        {volist name="unit" id="vo"}
                            <option value="{$vo.id}" {:$row.unit==$vo.id ? 'selected="selected"' : null } >{$vo.name}</option>
                        {/volist}
                    </select>
                </div>    

                <div class="form-group col-sm-6">
                    <span>颜色</span>
                    <select name="color" class="form-control comboSelect">
                        {volist name="color" id="vo"}
                            <option value="{$vo.id}" {:$row.color==$vo.id ? 'selected="selected"' : null } >{$vo.name}</option>
                        {/volist}
                    </select>
                </div>
<!-- 
                <div class="form-group col-sm-12">
                    <span>备注</span>
                    <textarea class="form-control" cols="5" name="desc">{$row.desc}</textarea>
                </div> -->

        </form>

    </section>

    <div class="form-group col-sm-12 panel-footer bg-none">
        <button type="button" class="btn btn-sm btn btn-primary" @click="save">  保 存 </button>
        <button type="reset" class="btn btn-sm btn-success ">  重 置 </button> 
    </div>



</div>
<!-- end -->


<script>
// seajs
seajs.use(['vendor/comboSelect/jquery.combo.select'],function() {


    var create = new Vue({
        el: '.edit',
        data: {
            location:[],
            location_id: '{$row.location}'
        },
        mounted: function(){
            var _this = this;
            $('.comboSelect').comboSelect();
            $('.depot').change(function(){
                _this.getLocation( $(this).val() );
            });
            $('.depot').change();
        },
        methods: {
            save: function () {
                var param = $(".form-edit").serializeArray();
                $.post("{:url('update')}", param, this.callback,'json');
            },
            callback:function (data) {
                if( data.error >0 ){
                    toastr.error(data.msg);
                }else{
                    toastr.success(data.msg);
                    Table.methods.refresh();
                    layer.closeAll('page');
                }
            },
            getLocation:function(id){
                var _this = this;
                $.getJSON("{:url('depot/getLocation')}?id="+id, function(data){
                    _this.location = data;
                });
            }
        }

    });

});
</script>